<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/common/layuimini/layui.css" media="all">
</head>
<body>
<div class="layui-form layui-form-pane" style="margin: 30px;">
  <h2 style="margin: 20px; font-weight: bold">保存草稿</h2>
  <div class="layui-form-item">
    <label class="layui-form-label">文章标题</label>
    <div class="layui-input-block">
      <input id="title" type="text" name="articleTitle" autocomplete="off" placeholder="请输入标题" class="layui-input" lay-verify="required" lay-reqtext="请输入文章标题">
    </div>
  </div>
  <div class="layui-btn-container" style="margin: 35px 10px;position: fixed;bottom: 0;right: 5%;">
    <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" onclick="closeRelease()">取消</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" lay-submit lay-filter="saveToDraftBtn">保存草稿</button>
  </div>
</div>
</body>
<script type="text/javascript" src="/common/layui/layui.js"></script>
<script type="text/javascript" src="/common/jquery-1.11.3.js"></script>
<script type="text/javascript" src="/common/xm-select/xm-select.js"></script>
<script type="text/javascript" src="/common/layer/layer.js"></script>
<script>

  $(document).ready(function(){
      //获取博客类型，给博客标题赋值
      checkArticleType();
  })

  function checkArticleType(){
      var articleId = parent.document.getElementById("articleId").value;
      var articleTitle = parent.document.getElementById("articleTitle").value;
      if (articleId != ''){
          $("#title").val(articleTitle);
      }
  }

  function closeRelease(){
    var index = parent.layer.getFrameIndex(window.name);//获取当前iframe层的索引
    parent.layer.close(index);//执行关闭
  }

  layui.use(['form'],function (){
    var form = layui.form;



    form.on('submit(saveToDraftBtn)',function (obj){
      var articleContent = $("#articleContent",parent.document).val();
      var data = obj.field;
      $.ajax({
        url:"/article/write/saveArticleToDraft",
        type: "post",
        dataType: "json",
        data: {
          "articleTitle" : data.articleTitle,
          "articleContent" : articleContent
        },
        success: function (res){
            if (res.state == true){
                var index = parent.layer.getFrameIndex(window.name);//获取当前iframe层的索引
                parent.layer.close(index);//执行关闭
                parent.window.location.href = "/";
            }else {
                layer.msg('保存失败',{icon:2,time:800})
            }
        }
      })
    })
  })
</script>
</html>
